home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 November: Tool Chest / Dev.CD Nov 94.toast / Tool Chest / Testing & Debugging / General tools / SourceObj / About SourceObj next >
Encoding:
Text File  |  1993-12-09  |  10.5 KB  |  263 lines  |  [TEXT/MPS ]

  1.  
  2.  
  3. Revision History
  4. ----------------
  5.  9 Dec 93    Renamed from UltraSlimFast to SourceObj to please Apple Legal Dept.
  6. 13 Oct 92    2.0a4 release
  7. 13 Oct 92        fix bug reading some records incorrectly
  8. 20 Aug 91   2.0a3 release
  9. 13 Aug 91       fix write to NIL bug
  10. 12 Aug 91    2.0a2 release
  11. 12 Aug 91        added Commando support, fix bug if source file does not end in CR
  12. 11 Aug 91       now read local label (type 18) records (e.g. labels in C)
  13. 29 July 91  2.0a1 release
  14.  
  15.  
  16.  
  17. What is it?
  18. -----------
  19. SourceObj is an MPW 3.x tool that reads .o files to
  20. produce a nice listing of source and assembly side by side.
  21. It works with Pascal, C, ObjectPascal, and C++ sources. 
  22.  
  23. It is useful for learning how the MPW compilers generate code.  
  24. UltraSlimFast 1.0 was used during the development of system 7.0 to 
  25. reduce the code size of the system.  It is also useful for people
  26. just learning assembly language, and it helps when you are in 
  27. Macsbug.  
  28.  
  29. Note:  UltraSlimFast 1.0 did not read .o files directly.  You
  30. had to use DumpObj to a temp file, then UltraSlimFast would read
  31. that temp file.  If you previously used UltraSlimFast 1.0, you will
  32. find this version much more convenient.
  33.  
  34.  
  35.  
  36. How to I use it?
  37. ----------------
  38. To use it you will need to compile with SADE symbols on. All it
  39. really needs is SADE line info, so "-sym on,novars,notypes" will 
  40. be slightly faster.
  41.  
  42. The following is an example of how to use it and some sample output:
  43.  
  44.     Pascal Foo.p -sym on,novars,notypes
  45.     SourceObj Foo.p.o 
  46.  
  47.  
  48.  
  49. What options are available?
  50. --------------------------------
  51.  
  52. SourceObj [option…] objectFile  > output ≥ progress
  53.     -a                    # show hex opcodes for each asm line
  54.     -class name              # show all modules with this class name
  55.     -f                    # don't show argument types in C++ unmangle names
  56.     -i directory          # search for source files  
  57.     -m name               # only show this module (not case sensitive)
  58.     -method name          # show all modules with this method name
  59.     -p                      # show progress info    
  60.     -symbols              # show Macsbug names at end of modules
  61.     -w                    # supress warning messages
  62.  
  63. And now, in more detail:
  64.  
  65. '-a'           To save space, the hex opcodes for each assembly line is, by 
  66.                default, not shown.  This force the hex opcodes to be shown.
  67.      
  68. '-class name'  Filters to only show modules for a specified class.  Useful
  69.                when using ObjectPascal or C++.
  70.                Example:  SourceObj MyOOPstuff.cp.o -class TDocument
  71.               
  72. '-f'           Unmangled C++ names tend to be long because they show the 
  73.                parameter types.  This can make the disassembled code spill 
  74.                over into the source area.  This option removes the parameter   
  75.                types. Example:  "JSR  Foo(short, long)"   becomes   "JSR   Foo"
  76.  
  77. '-i directory' A directory to search in when looking for source files.
  78.  
  79. '-m name'      Filters to show only one module.  This is not particularly 
  80.                case sensitive, so Pascal programmers don't have to 
  81.                uppercase names like DumpObj requires.
  82.  
  83. '-method name' Filters to only show modules of a specified method.  Useful
  84.                when using ObjectPascal or C++.
  85.                Example:  SourceObj MyOOPstuff.cp.o -method Free
  86.                
  87. '-p'           Shows random internal progress info.  If you are really
  88.                brave, try '-v' (verbose).
  89.                
  90. '-symbols'     Shows the bytes at the end of a module that MacsBug uses
  91.                to show module names.  
  92.                
  93. '-w'           Suppress warning messages.
  94.  
  95.  
  96.  
  97.  
  98. Are there any known problems?
  99. -----------------------------
  100. As of the alpha 1 release, this is the bugs I know about:
  101.  
  102. Complicated "while" and "switch" statements in C can confuse SourceObj,
  103. resulting in misaligned output. (Actually, if you looked at the source
  104. records the MPW C compiler generates in those cases, you'd be confused too.)
  105.  
  106. When using '-m name' with C++, you have to type the mangled name.  Sorry.
  107.  
  108. Imbedded string constants at the end of modules are not disassembled 
  109. in a very smart way.
  110.  
  111.  
  112.  
  113. What if I have suggestions, comments, or bug reports?
  114. -----------------------------------------------------
  115. Please send me any ideas or suggestions you have.  
  116.  
  117.  
  118.  
  119. What is the legal status of this?
  120. ---------------------------------
  121. This is not an official Apple product.  I wrote it because I thought
  122. it would be useful.  If you like it, feel free to pass this text file
  123. and the tool on to others.
  124.  
  125.  
  126. -Nick Kledzik
  127. 29 July 91
  128.  
  129. AppleLink: NICK
  130. Internet:  kledzik@apple.com
  131.  
  132.  
  133.  
  134. How about some examples?
  135. ------------------------
  136.  
  137.  
  138. SourceObj :Objects:Procedure.cp.o  -a -method GetBlankAsmLine 
  139.  
  140. 0000: 4E56 0000   LINK      A6,#$0000         void TProcedure::GetBlankAsmLine(char* asmStr)
  141. 0004: 48E7 0308   MOVEM.L   D6/D7/A4,-(A7)    {
  142. 0008: 286E 000C   MOVEA.L   $000C(A6),A4          int     asmWidth;
  143.                                                     
  144. 000C: 4A2D 0000   TST.B     $0000(A5)             if ( gShowOpcodes )
  145. 0010: 6704        BEQ.S     $0016             
  146. 0012: 7C30        MOVEQ     #$30,D6                   asmWidth = 48;    // 48 = asm line width with opcodes
  147. 0014: 6002        BRA.S     $0018                 else
  148. 0016: 7C24        MOVEQ     #$24,D6                   asmWidth = 36;    // 36 = asm line width without opcodes
  149.                                                     
  150. 0018: 7E00        MOVEQ     #$00,D7               for (int i=0; i<asmWidth; i++)        
  151. 001A: 6008        BRA.S     $0024             
  152. 001C: 18FC 0020   MOVE.B    #$20,(A4)+                *asmStr++ = ' ';
  153. 0020: 2007        MOVE.L    D7,D0             
  154. 0022: 5287        ADDQ.L    #$1,D7            
  155. 0024: BC87        CMP.L     D7,D6             
  156. 0026: 6EF4        BGT.S     $001C             
  157. 0028: 4214        CLR.B     (A4)                  *asmStr = '\0';
  158. 002A: 4CEE 10C0…  MOVEM.L   -$000C(A6),D6/D7/A4}
  159. 0030: 4E5E        UNLK      A6                
  160. 0032: 4E75        RTS                         
  161. 0056: 0000        DC.W      $0000             
  162.  
  163.  
  164.  
  165. SourceObj "{UEdition}.Debug Files:UEdition.p.o" -i "{UEdition}" -symbols -method Clone
  166.                                     
  167.                                     {$S ARes}
  168.                                     FUNCTION TSection.Clone: TObject; OVERRIDE;
  169.                                     VAR
  170.                                         meToo:                TSection;
  171.                                         newSectionH:        SectionHandle;
  172.                                         newAliasH:            AliasHandle;
  173.                                         anErr:                OSErr;
  174. 0000:   LINK      A6,#$FFF0             aliasWasChanged:    BOOLEAN;
  175. 0004:   MOVEA.L   A7,A0             BEGIN
  176. 0006:   MOVE.W    #$0007,D0             { shallow clone }
  177. 000A:   MOVE.W    #$7267,(A0)+      
  178. 000E:   DBF       D0,$000A          
  179. 0012:   MOVEM.L   D6/D7/A2-A4,-(A7) 
  180. 0016:   JSR       %_BP              
  181. 001A:   MOVE.L    $0008(A6),D6      
  182. 001E:   MOVE.L    #'rgrg',-(A7)         meToo := TSection(INHERITED Clone);
  183. 0024:   MOVE.L    #'rgrg',-(A7)         
  184. 002A:   MOVE.L    D6,-(A7)              { clone SectionRecord }
  185. 002C:   JSR       TOBJECT_CLONE     
  186. 0030:   PEA       $0034             
  187. 0034:   JSR       %_OBCHK           
  188. 0038:   MOVEA.L   (A7)+,A3          
  189. 003A:   MOVEA.L   D6,A0                 newSectionH := SELF.fSectionH;
  190. 003C:   MOVEA.L   (A0),A0           
  191. 003E:   MOVE.L    $0006(A0),-$0008(A6)
  192. 0044:   MOVE.W    #$7267,-(A7)          FailOSErr(HandToHand(Handle(newSectionH)));
  193. 0048:   PEA       -$0008(A6)            
  194. 004C:   JSR       HANDTOHAND            { clone AliasRecord }
  195. 0050:   JSR       FAILOSERR         
  196. 0054:   MOVEA.L   D6,A0                 newAliasH := SELF.fSectionH^^.alias;
  197. 0056:   MOVEA.L   (A0),A0           
  198. 0058:   MOVEA.L   $0006(A0),A1      
  199. 005C:   MOVEA.L   (A1),A1           
  200. 005E:   MOVE.L    $0010(A1),-$000C(A6)
  201. 0064:   MOVE.W    #$7267,-(A7)          FailOSErr(HandToHand(Handle(newAliasH)));
  202. 0068:   PEA       -$000C(A6)            
  203. 006C:   JSR       HANDTOHAND            { connect together }
  204. 0070:   JSR       FAILOSERR         
  205. 0074:   MOVEA.L   -$0008(A6),A0         newSectionH^^.alias := newAliasH;
  206. 0078:   MOVEA.L   (A0),A0           
  207. 007A:   MOVE.L    -$000C(A6),$0010(A0)
  208. 0080:   MOVEA.L   (A3),A0               meToo.fSectionH := newSectionH;
  209. 0082:   MOVE.L    -$0008(A6),$0006(A0)
  210. 0088:   MOVEA.L   -$0008(A6),A1         newSectionH^^.refCon := ORD(meToo);
  211. 008C:   MOVEA.L   (A1),A1           
  212. 008E:   MOVE.L    A3,$000C(A1)          { give clone a new SectionID }
  213. 0092:   MOVEA.L   $0002(A0),A4          WITH meToo.fDocument DO
  214. 0096:   MOVEA.L   (A4),A1               BEGIN
  215. 0098:   MOVE.L    $0094(A1),D0              fSectionIDcounter := fSectionIDcounter + 1;
  216. 009C:   ADDQ.L    #$1,D0            
  217. 009E:   TRAPV                       
  218. 00A0:   MOVE.L    D0,$0094(A1)      
  219. 00A4:   MOVEA.L   -$0008(A6),A2             newSectionH^^.SectionID := fSectionIDcounter;
  220. 00A8:   MOVEA.L   (A2),A2               END;
  221. 00AA:   MOVE.L    $0094(A1),$0008(A2)    
  222.                                         { have it owned by no document }
  223. 00B0:   MOVEQ     #$00,D0               meToo.fDocument := NIL;
  224. 00B2:   MOVE.L    D0,$0002(A0)      
  225. 00B6:   MOVE.B    $0000(A5),D0          IF gHasEditionManager THEN
  226. 00BA:   BEQ.S     $00FE             
  227. 00BC:   MOVE.W    #$7267,-(A7)          BEGIN
  228. 00C0:   CLR.L     -(A7)                     anErr := RegisterSection(FSSpecPtr(NIL)^,
  229. 00C2:   MOVE.L    -$0008(A6),-(A7)                                  newSectionH, aliasWasChanged);
  230. 00C6:   PEA       -$000F(A6)        
  231. 00CA:   MOVE.W    #$0604,D0         
  232. 00CE:   _Pack11                     
  233. 00D0:   MOVE.W    (A7)+,D7          
  234. 00D2:   TST.W     D7                        IF (anErr <> noErr) 
  235. 00D4:   SNE       D0                            & (anErr <> containerNotFoundWrn) 
  236. 00D6:   TST.B     D0                            & (anErr <> notThePublisherWrn) 
  237. 00D8:   BEQ.S     $00FE             
  238. 00DA:   CMPI.W    #$FE33,D7         
  239. 00DE:   SNE       D1                
  240. 00E0:   AND.B     D1,D0             
  241. 00E2:   BEQ.S     $00FE             
  242. 00E4:   CMPI.W    #$FE31,D7         
  243. 00E8:   SNE       D1                
  244. 00EA:   AND.B     D1,D0             
  245. 00EC:   BEQ.S     $00FE             
  246. 00EE:   CMPI.W    #$FE34,D7         
  247. 00F2:   SNE       D1                
  248. 00F4:   AND.B     D1,D0             
  249. 00F6:   BEQ.S     $00FE             
  250. 00F8:   MOVE.W    D7,-(A7)                      & (anErr <> multiplePublisherWrn) THEN FailOSErr(anErr);
  251. 00FA:   JSR       FAILOSERR                 {### should we warn user of duplicate publisher ??}
  252.                                         END; {if}
  253.                                         
  254. 00FE:   MOVE.L    A3,$000C(A6)          Clone := meToo;
  255. 0102:   JSR       %_EP              END; { Clone }
  256. 0106:   MOVEM.L   (A7)+,D6/D7/A2-A4 
  257. 010A:   UNLK      A6                
  258. 010C:   MOVE.L    (A7)+,(A7)        
  259. 010E:   RTS                         
  260. 0110:   DC.B      $80+$0E, 'TSECTION.CLONE', $00
  261. 0120:   DC.W      $0000             
  262.  
  263.